<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <p>名字</p>
        <button class="btn-left">开始</button>
        <button class="btn-right">结束</button>


        <script>

            const arr = ["刘宏伟", "周美芸", "朱俊玮", "郭世芳", "吴慧玉"]
            const p = document.querySelector('p')
            const btnl = document.querySelector('.btn-left')
            const btnr = document.querySelector('.btn-right')

            let time = 0
            let random = 0

            btnl.addEventListener('click', function () {
                time = setInterval(function () {
                    random = Math.floor(Math.random() * arr.length)
                    p.innerHTML = arr[random]
                }, 100)

                if (arr.length === 1) {
                    btnl.disabled = 'true'
                    btnr.disabled = 'true'
                    alert('只剩下一个元素')
                }
            })

            btnr.addEventListener('click', function () {
                clearInterval(time)
                arr.splice(arr[random], 1)
                console.log(arr)
            })





        </script>
    </div>
</body>

</html>